/* Build by fuyun@5173.com 
Date:2014-07-18 10:19:57 
Version:1.00 */
var sixcache_time = 600;
var sixrandom = (new Date).getTime();
var sixdoor_api = "http://trading.5173.com:8080/auction/NewPublishJson.aspx";
var sixdoor_search_api = "http://trading.5173.com:8080/browse/KeywordSearch.aspx?action=sellsearchnew&sixrdm=" + sixrandom + "&cache=" + sixcache_time;
var sixdoor_preval_api = "http://trading.5173.com:8080/auction/NewPublishJson.aspx?action=getBasicType&sixrdm=" + sixrandom + "&cache=" + sixcache_time;
var sixdoor_ul_finded = false;
(function ($) {
    $.sixdoor = $.sixdoor || {};
    $.extend($.sixdoor, {
        loadData: function (url, jsonpcall, callback) {
            var fun = callback;
            $.ajax({
                type: "GET", url: url, dataType: "jsonp", jsonp: "jsoncallback", scriptCharset: "GBK", jsonpCallback: jsonpcall, cache: true, success: function (data) {
                    fun(data)
                }
            })
        }, li_hoverIn: function () {
            var doorindex = parseInt($(this).attr("index_1"), 10);
            var itemIndex = parseInt($(this).attr("index_2"), 10);
            var data = doorData[doorindex];
            var _item = data.child[itemIndex];
            if (_item.enable) {
                $(this).addClass("noncebox");
                var tip = _item.tip;
                if (tip)
                    $.sixdoor.showTips($(this), tip, 2);
                else
                    $.sixdoor.hideTips()
            }
        }, li_hoverOut: function () {
            $(this).removeClass("noncebox")
        }, renderDoor_click: function () {
            $(this).parent().find("li").removeClass("onbox");
            $(this).addClass("onbox");
            var doorindex = parseInt($(this).attr("index_1"), 10);
            var itemIndex = parseInt($(this).attr("index_2"), 10);
            var data$$9 = doorData[doorindex];
            var _item = data$$9.child[itemIndex];
            var nextApiUrl = sixdoor_api + "?action=" + data$$9.nextAction + "&sixrdm=" + sixrandom + "&cache=" + sixcache_time + "&" + data$$9.type + "=" + _item.id;
            if (data$$9.nextParas && data$$9.nextParas.length > 0)
                nextApiUrl = nextApiUrl + "&" + data$$9.nextParas;
            var nextAction = data$$9.nextAction;
            var canPublish = data$$9.canPublish;
            var publishUrl = data$$9.url;
            var id = _item.id;
            var name = _item.name;
            var type = data$$9.type;
            var currItem = { id: id, name: name, type: type };
            doorData[doorindex].selectValue = currItem;
            var typearry = new Array;
            var notfind_gm = "";
            var notfind_ga = "";
            for (var t = 0; t <= doorindex; t++) {
                typearry.push(doorData[t].selectValue);
                var tempItem = doorData[t].selectValue;
                if (tempItem.type == "gm")
                    notfind_gm = tempItem.id;
                else if (tempItem.type == "ga")
                    notfind_ga = tempItem.id
            }
            var notFindUrl = "http://trading.5173.com/UpInfo/UpGameAreaServer.aspx?gm=" + notfind_gm + "&ga=" + notfind_ga;
            $("#notfind").attr("href", notFindUrl);
            if (canPublish == 1) {
                $.sixdoor.showCurrInfo();
                $("#btnPulish").attr("class", "btn_Normal").attr("disabled", false);
                $("#btnPulish").click(function () {
                    $.sixdoor.showCurrInfo();
                    if (type == "race")
                        publishUrl = publishUrl + "&raceid=" + id;
                    window.location.href = publishUrl
                })
            } else {
                $("#btnPulish").attr("class", "btn_disabled").attr("disabled", true);
                var nextIndex = doorindex + 1;
                $.sixdoor.showWait();
                $.sixdoor.loadData(nextApiUrl, nextAction, function (data) {
                    $.sixdoor.hideWait();
                    if (data.child.length == 0 && data.canPublish == 1) {
                        $("#btnPulish").attr("class", "btn_Normal").attr("disabled", false);
                        $("#btnPulish").click(function () {
                            $.sixdoor.showCurrInfo();
                            window.location.href = data.url
                        });
                        var exitsDivs = $("#fed_doorbox").children("div");
                        $(exitsDivs).each(function (index) {
                            if (index >= nextIndex)
                                $(this).remove()
                        })
                    } else {
                        doorData[nextIndex] = data;
                        $.sixdoor.renderDoor(nextIndex);
                        $.sixdoor.showCurrInfo();
                        var index$$33 = nextApiUrl.indexOf("basictype=");
                        var basictype = nextApiUrl.substr(index$$33);
                        if (basictype == "basictype=Money" && nextAction == "getTS") {
                            var $secondDoorList = $("#fed_doorbox .sortList_step").eq(1).find("ul");
                            setTimeout(function () {
                                $('<li spell="\u5927\u5356\u5bb6\u5165\u53e3" style="color:red;" href="#">\u5927\u5356\u5bb6\u5165\u53e3</li>').click(function () {
                                    window.location.href = "http://yxbmall.5173.com/applySeller.html"
                                }).appendTo($secondDoorList)
                            }, 100)
                        }
                    }
                })
            }
        }, hideWait: function () {
            $("#load_layer").hide();
            $("#load_cover").hide()
        }, showWait: function () {
            $("#load_layer").show();
            $("#load_cover").show()
        }, renderDoorFor: function (items, data$$9, doorindex, offset, count) {
            if (items.length < offset + count)
                return "";
            var html_str = "";
            for (var i = 0; i < count; i++) {
                var item = items[i + offset];
                var _class = "";
                html_str += "<li";
                if (item.enable == false)
                    _class = "no-run";
                if (data$$9.selectValue) {
                    var selectItem = data$$9.selectValue;
                    if (selectItem.id == item.id) {
                        _class += "onbox";
                        sixdoor_ul_finded = true
                    }
                }
                if (_class)
                    html_str += " class='" + _class + "'";
                html_str += " spell='" + item.spell + "'";
                html_str += " index_1='" + doorindex + "'";
                html_str += " index_2='" + (i + offset) + "'>";
                if (item.redirectUrl)
                    html_str += "<a href='" + item.redirectUrl + "' >" + item.name + "</a>";
                else
                    html_str += item.name;
                html_str += "</li>"
            }
            return html_str
        }, renderDoor: function (doorindex) {
            var exitsDivs = $("#fed_doorbox").children("div");
            $(exitsDivs).each(function (index) {
                if (index >= doorindex)
                    $(this).remove()
            });
            var data = doorData[doorindex];
            var $oneDoor = $("<div  class='sortList_step' name='door'></div>");
            var $input = $("<input type='text' id='input_keywords_" + doorindex + "' name='keywords' maxlength='10' class='sortsearch' placeholder='\u8f93\u5165\u4e2d\u6587\u6216\u62fc\u97f3\u9996\u5b57\u6bcd'  >");
            $input.fedPlaceHoder("holderfont");
            $oneDoor.append($("<div class='sortsearchbox'></div>").append($input));
            var $ul = $("<ul></ul>");
            var data$$9 = doorData[doorindex];
            var items = data$$9.child;
            var fisrtForCount = items.length > 20 ? 20 : items.length;
            $ul.append($.sixdoor.renderDoorFor(items, data$$9, doorindex, 0, fisrtForCount));
            $oneDoor.append($ul);
            $("#fed_doorbox").append($oneDoor);
            setTimeout(function () {
                $ul.append($.sixdoor.renderDoorFor(items, data$$9, doorindex, 20, items.length - 20));
                $ul.append('<li class="no_find_game_tips hide">\u62b1\u6b49\uff0c\u6ca1\u6709\u627e\u5230\uff1a<span></span> \u76f8\u5173\u7684\u6e38\u620f\u54e6\u3002</li>');
                if (!sixdoor_ul_finded && data$$9.selectValue)
                    $ul.scrollTop(29);
                $ul.children().click($.sixdoor.renderDoor_click).hover($.sixdoor.li_hoverIn, $.sixdoor.li_hoverOut)
            }, 10);
            var $inputTip = $("#alertbox");
            if ($inputTip.length == 0) {
                $inputTip = $("<div class='alertbox' id='alertbox'><p>\u8bf7\u9009\u62e9\u6e38\u620f\u670d</p></div>");
                $("body").append($inputTip)
            }
            $inputTip.html("<p>\u8bf7\u9009\u62e9" + data.name + "</p>");
            $inputTip.fedFollow($input, { left: 0, top: -50 });
            $input.data("inputIndex", doorindex);
            $input.bind("keyup change", function () {
                var inputIndex = parseInt($(this).data("inputIndex"));
                var inputValue = $.trim($(this).val()).toLocaleLowerCase();
                var $ul = $(this).parent().parent();
                var $no_tips = $(this).closest(".sortList_step").find("ul .no_find_game_tips");
                if (inputValue == "" || inputValue == "\u8f93\u5165\u4e2d\u6587\u6216\u62fc\u97f3\u9996\u5b57\u6bcd") {
                    $ul.find("li").show();
                    $no_tips.hide()
                } else {
                    $ul.find("li").hide();
                    $ul.find("li[spell*='" + inputValue + "']").show();
                    if ($ul.find("li[spell*='" + inputValue + "']").length == 0) {
                        $no_tips.show();
                        $no_tips.find("span").html($(this).val())
                    } else
                        $no_tips.hide()
                }
            });
            $input.mouseenter(function () {
                $.sixdoor.hideTips()
            });
            if (doorindex >= 6) {
                $("#alertbox").hide();
                var lastLeft = parseInt($("#fed_doorbox").css("left").replace("px", ""));
                if (lastLeft >= -(doorindex - 6) * 161)
                    $("#fed_doorbox").animate({ left: "-=161px" }, 400, function () {
                        $("#alertbox").fedFollow("#input_keywords_" + doorindex, { left: 0, top: -50 })
                    });
                if ($("#doorLeftBtn").attr("class") == "glide_left_off") {
                    $("#doorLeftBtn").attr("class", "glide_left_on");
                    $("#doorLeftBtn").bind("click", function () {
                        var state = $("#doorLeftBtn").data("state");
                        if (!state || state == 0) {
                            state = 1;
                            $("#doorLeftBtn").data("state", state);
                            var lastLeft = parseInt($("#fed_doorbox").css("left").replace("px", ""));
                            $("#doorRightBtn").attr("class", "glide_right_on");
                            if (lastLeft < 0)
                                $("#fed_doorbox").animate({ left: "+=161px" }, 400, function () {
                                    if (parseInt($("#fed_doorbox").css("left").replace("px", "")) < (doorindex - 6) * 161)
                                        $("#alertbox").fedFollow("#input_keywords_" + doorindex, { left: 0, top: -50 });
                                    else
                                        $("#alertbox").hide();
                                    $("#doorLeftBtn").attr("class", "glide_left_off");
                                    $("#doorLeftBtn").data("state", 0)
                                });
                            else
                                $("#doorLeftBtn").data("state", 0)
                        }
                    });
                    $("#doorRightBtn").bind("click", function () {
                        var state = $("#doorRightBtn").data("state");
                        if (!state || state == 0) {
                            state = 1;
                            $("#doorRightBtn").data("state", state);
                            var lastLeft = parseInt($("#fed_doorbox").css("left").replace("px", ""));
                            $("#doorLeftBtn").attr("class", "glide_left_on");
                            if (lastLeft >= (doorindex - 6) * 161)
                                $("#fed_doorbox").animate({ left: "-=161px" }, 400, function () {
                                    if (parseInt($("#fed_doorbox").css("left").replace("px", "")) < (doorindex - 6) * 161)
                                        $("#alertbox").fedFollow("#input_keywords_" + doorindex, { left: 0, top: -50 });
                                    else
                                        $("#alertbox").hide();
                                    $("#doorRightBtn").attr("class", "glide_right_off");
                                    $("#doorRightBtn").data("state", 0)
                                });
                            else
                                $("#doorRightBtn").data("state", 0)
                        }
                    })
                }
            } else {
                $("#doorLeftBtn").attr("class", "glide_left_off");
                $("#doorRightBtn").attr("class", "glide_right_off");
                $("#doorLeftBtn").unbind("click");
                $("#doorRightBtn").unbind("click");
                lastLeft = parseInt($("#fed_doorbox").css("left").replace("px", ""));
                if (lastLeft < 0)
                    $("#fed_doorbox").animate({ left: "0px" }, 400, function () {
                        if (parseInt($("#fed_doorbox").css("left").replace("px", "")) < (doorindex - 6) * 161)
                            $("#alertbox").fedFollow("#input_keywords_" + doorindex, { left: 0, top: -50 });
                        else
                            $("#alertbox").hide()
                    })
            }
        }, showTips: function (obj, tip, type) {
            var $tipdiv = $("#fed_sixtip");
            if ($tipdiv.length == 0) {
                $tipdiv = $("<div id='fed_sixtip' class='fed-toolstip'></div>").hide();
                $("body").append($tipdiv)
            }
            $tipdiv.empty().html("<div class='fed-tipcon'><p>" + tip + "</p></div><div class='fed-tipsarr fed-arrbottom'><span class='arr-3'>\u25c6</span><span class='arr-1'>\u25c6</span><span class='arr-2'>\u25c6</span></div>");
            if (type == 1) {
                var top = 0 - $tipdiv.height() - 53;
                $tipdiv.fedFollow($(obj), { left: -10, top: top })
            } else if (type == 2) {
                top = 0 - $tipdiv.height() - 43;
                $tipdiv.fedFollow($(obj), { left: 30, top: top })
            }
            $tipdiv.mouseleave(function () {
                $tipdiv.hide()
            })
        }, hideTips: function () {
            $("#fed_sixtip").hide()
        }, search: function (keyword) {
            var url = sixdoor_search_api + "&keyword=" + escape(keyword);
            $.sixdoor.loadData(url, "searchkey", function (data) {
                var len = data.length;
                $("#search_panel").show();
                var $box = $("#search_box").empty();
                if (len == 0)
                    $box.html(" <div class='search_false'> <span class='icon'></span>" + "<p>\u6ca1\u6709\u627e\u5230<strong> \u201c" + keyword + "\u201d</strong> \u7684\u76f8\u5173\u6e38\u620f\u6216\u5546\u54c1\u54e6\uff01\u8bf7\u60a8\u6362\u4e2a\u5173\u952e\u8bcd\u8bd5\u8bd5\u3002</p>" + "<ul>" + "<li class='title_tips'>\u5efa\u8bae\u60a8\uff1a</li>" + "<li>1. \u770b\u770b\u60a8\u8f93\u5165\u7684\u5173\u952e\u8bcd\u662f\u5426\u6709\u8bef\uff1b</li>" + "<li>2. \u5728\u6e38\u620f\u540d\u79f0\u548c\u51fa\u552e\u65b9\u5f0f\u95f4\u589e\u52a0\u7a7a\u683c\uff1a\u5982\u201c\u9b54\u517d\u88c5\u5907\u201d\u6539\u6210\u201c\u9b54\u517d \u88c5\u5907\u201d\uff1b</li>" + "<li>3. \u4f7f\u7528\u7c7b\u4f3c\u5173\u952e\u8bcd\uff1a\u5929\u9f99\u516b\u90e8 \u5e10\u53f7 \uff0c\u9f99\u4e4b\u8c37 \u6e38\u620f\u5e01\uff0c\u95ee\u9053 \u88c5\u5907\u3002</li>" + "</ul>" + "</div>");
                else
                    for (var i = 0; i < data.length; i++) {
                        var item = data[i];
                        var itemname = item.name.replace(keyword, "<span>" + keyword + "</span>");
                        var $p = $("<p>" + itemname + "</p>");
                        $p.data("paras", item.paras);
                        $p.hover(function () {
                            $(this).addClass("nonce_s")
                        }, function () {
                            $(this).removeClass("nonce_s")
                        });
                        $p.click(function () {
                            var paras = $(this).data("paras");
                            var preurl = sixdoor_preval_api + "&" + paras;
                            $.sixdoor.predoor(preurl);
                            $("#search_panel").hide();
                            $("#search_box").empty()
                        });
                        $box.append($p)
                    }
            })
        }, predoor: function (preurl) {
            $.sixdoor.loadData(preurl, "searchbykey", function (data) {
                doorData = data;
                for (var i = 0; i < doorData.length; i++) {
                    $.sixdoor.renderDoor(i);
                    if (doorData[i].url != "") {
                        $("#btnPulish").attr("class", "btn_Normal").attr("disabled", false);
                        $("#btnPulish").click(function () {
                            window.location.href = tempNextData.url
                        });
                        break
                    } else {
                        var tempNextIndex = i + 1;
                        if (tempNextIndex <= doorData.length - 1) {
                            tempNextData = doorData[tempNextIndex];
                            if (tempNextData.canPublish == 1 && tempNextData.child.length == 0) {
                                $("#btnPulish").attr("class", "btn_Normal").attr("disabled", false);
                                $("#btnPulish").click(function () {
                                    window.location.href = tempNextData.url
                                });
                                break
                            }
                        }
                    }
                }
                $.sixdoor.showCurrInfo()
            })
        }, showCurrInfo: function () {
            var currInfo = "";
            var doorNum = $("div[name='door']").length;
            for (var i = 0; i < doorData.length; i++) {
                var doorItem = doorData[i];
                if (doorItem.selectValue && i < doorNum) {
                    if (currInfo != "")
                        currInfo = currInfo + " &gt; ";
                    currInfo = currInfo + doorItem.selectValue.name
                }
            }
            $("#currSeleted").html(currInfo)
        }, showHistory: function () {
            if (historyinfos && historyinfos.length > 0) {
                $("#select_layer .clear_game").html("<a href='#'>\u6e05\u7a7a</a>");
                var $historyBox = $("#divPublishHistoryList");
                $historyBox.empty().show();
                for (var i = 0; i < historyinfos.length; i++) {
                    var item = historyinfos[i];
                    var $itemdom = $("<li lang=" + item.id + "><span class='game_info'>" + item.name + "</span><a href='#' class='close'></a></li>");
                    $itemdom.data("paras", item.paras);
                    $itemdom.mouseover(function () {
                        var $self = $(this);
                        $itemdom.removeClass("current");
                        $self.addClass("current")
                    });
                    $itemdom.mouseout(function () {
                        var $self = $(this);
                        $self.removeClass("current")
                    });
                    $itemdom.click(function (event) {
                        var preurl = sixdoor_preval_api + "&" + $(this).data("paras");
                        $.sixdoor.predoor(preurl);
                        $historyBox.parent().hide();
                        $("#liSelectedPublishHistory").removeClass("select_current").end().html($(this).html());
                        event.stopPropagation();
                        return false
                    });
                    $itemdom.find(".close").click(function () {
                        var $li = $(this).closest("li");
                        id = $li.attr("lang");
                        $li.remove();
                        UpdatePublishedHistory(id);
                        return false
                    });
                    $(".clear_game a").live("click", function () {
                        $("#divPublishHistoryList").html("");
                        $(this).closest(".clear_game").html("\u60a8\u8fd8\u6ca1\u6709\u53d1\u5e03\u8fc7\u5546\u54c1\u54e6");
                        $(this).remove();
                        DeletePublishedHistory();
                        return false
                    });
                    $historyBox.append($itemdom)
                }
            } else
                $("#select_layer .clear_game").html("\u60a8\u8fd8\u6ca1\u6709\u53d1\u5e03\u8fc7\u5546\u54c1\u54e6")
        }
    })
})(jQuery);
$(function () {
    for (var i = 0; i < doorData.length; i++) {
        $.sixdoor.renderDoor(i);
        $.sixdoor.showCurrInfo()
    }
    var doorindex = 0;
    $("#searchInput").fedPlaceHoder("holderfont");
    $("#searchInput").keyup(function (event) {
        $("#searchInput").removeClass("keywords_search_txt_default");
        if (event.keyCode == 13)
            if ($("#searchInput").val() != "" && $("#searchInput").val() != $("#searchInput").attr("placeholder"))
                $.sixdoor.search($("#searchInput").val())
    });
    $("#btnSearch").click(function () {
        if ($("#searchInput").val() != "" && $("#searchInput").val() != $("#searchInput").attr("placeholder"))
            $.sixdoor.search($("#searchInput").val())
    });
    $("#searchbtn_close").click(function () {
        $("#search_panel").hide();
        $("#search_box").empty()
    });
    $("#liSelectedPublishHistory").click(function () {
        var $self = $(this);
        if (!$("#divPublishHistoryList").find("li") == true)
            $("#select_layer .clear_game").html("\u60a8\u8fd8\u6ca1\u6709\u53d1\u4e0d\u8fc7\u5546\u54c1\u54e6");
        else
            $("#select_layer .clear_game").html("<a href='#'>\u6e05\u7a7a</a>");
        if ($self.hasClass("select_current")) {
            $("#select_layer").hide();
            $self.removeClass("select_current")
        } else {
            $self.addClass("select_current");
            $("#select_layer").show();
            $.sixdoor.showHistory()
        }
    });
    $("#batbtn").hover(function () {
        $("#battips").fedFollow("#batbtn", { left: 0, top: 0 })
    }, function () {
        $("#battips").hide()
    });
    $("body").click(function (e) {
        var id = $(e.target).attr("id");
        if (id != "liSelectedPublishHistory" && id != "divPublishHistoryList") {
            $("#select_layer").hide();
            $("#liSelectedPublishHistory").removeClass("select_current")
        }
    });
    if (historyinfos)
        if (historyinfos.length > 0)
            $("#liSelectedPublishHistory").html(historyinfos[0].name);
    $("#load_layer").after($(" <div class='load_cover hide' id='load_cover'></div>"));
    var vote_entrance = {
        isIE6: navigator.userAgent.toLowerCase().indexOf("msie 6.0") !== -1, show: function (html) {
            var c = $("<div></div>").html(html);
            if (this.isIE6)
                c.css({ position: "absolute", left: "0", top: "230px" });
            else
                c.css({ position: "fixed", left: "0", top: "230px" });
            $("body").append(c)
        }
    };
    vote_entrance.show('<a href="http://question.5173.com/main/Index.aspx?id=7a31753783e740e093675c3949791385" target="_blank"><img alt="\u95ee\u5377" src="http://images001.5173cdn.com/images/common/1m/vote_in_1.png" /></a>')
});

